package com.kd.juhaowan.ui;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallbackProxy;
import com.kd.juhaowan.R;
import com.kd.juhaowan.http.api.CommonApi;
import com.kd.juhaowan.http.model.HttpListData2;
import com.kd.juhaowan.http.model.MineGiftModel;
import com.kd.juhaowan.ui.adapter.BaseRecyclerViewAdapter;
import com.kd.juhaowan.ui.holder.MineGiftViewHolder;

import butterknife.BindView;
import butterknife.OnClick;

public class MineGiftActivity extends BaseActivity {




    @BindView(R.id.gift_listview)
    RecyclerView recyclerView;

    private BaseRecyclerViewAdapter<MineGiftViewHolder, MineGiftModel> giftAdapter;
    @BindView(R.id.activity_title)
    TextView titleView;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        titleView.setText("我的礼包");
        initAdapter();
//        setContentView(R.layout.activity_account_login);
        EasyHttp.post(this).api(new CommonApi("api/user/giftPack")).request(new HttpCallbackProxy<HttpListData2<MineGiftModel>>(this){
            @Override
            public void onHttpSuccess(HttpListData2<MineGiftModel> result, boolean cache) {

                super.onHttpSuccess(result, cache);
                giftAdapter.resetAdapterData(result.getData());

            }
        });
    }

    @Override
    protected void reInitDate() {
        EasyHttp.post(this).api(new CommonApi("api/user/giftPack")).request(new HttpCallbackProxy<HttpListData2<MineGiftModel>>(this){
            @Override
            public void onHttpSuccess(HttpListData2<MineGiftModel> result, boolean cache) {

                super.onHttpSuccess(result, cache);
                giftAdapter.resetAdapterData(result.getData());

            }
        });
    }

    @OnClick(R.id.actvity_back)
    public void onBackClick(){
        finish();
    }
    @Override
    protected int getViewLayoutResourceId() {
        return R.layout.activity_mine_gift;
    }

    private void initAdapter(){
        giftAdapter = new BaseRecyclerViewAdapter<MineGiftViewHolder, MineGiftModel>() {
            @NonNull
            @Override
            public MineGiftViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                LayoutInflater inflater = LayoutInflater.from(parent.getContext());
                View view = inflater.inflate(R.layout.item_mine_gift, null, false);
                MineGiftViewHolder holder=new MineGiftViewHolder(view);
                holder.setOnItemClickListener(getOnItemClickListener());
                return  holder;

            }

            @Override
            public void onBindViewHolder(@NonNull MineGiftViewHolder holder, int position) {
                holder.setDate(getItem(position));

            }
        };
        giftAdapter.setOnItemClickListener(null);
        giftAdapter.resetAdapterData(null);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(RecyclerView.VERTICAL);

        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(giftAdapter);



    }


}
